<template>
  <q-page class="cc-admin">
    <div class="col bg-white shadow-2 q-pa-md q-ma-sm">
      <q-table
        flat
        color="primary"
        class="cross_table"
        separator="cell"
        :columns="columns"
        :data="list"
        row-key="id"
        :pagination.sync="pagination"
        :visible-columns="group"
        @request="query"
        :rows-per-page-options="[10, 20, 50, 100]"
        :loading="loading"
        :selection="mobile?'none':'multiple'"
        :selected.sync="selected"
      >
        <template v-slot:top="table">
          <div class="row no-wrap full-width">
            <q-input
              clearable
              outlined
              dense
              placeholder="请输入关键字搜索"
              class="on-left"
              @input="query"
              debounce="500"
              v-model="key"
            >
              <template #append>
                <q-btn
                  flat
                  round
                  icon="search"
                  color="primary"
                  @click="query"
                  :loading="loading"
                >
                  <q-tooltip>搜索</q-tooltip>
                </q-btn>
              </template>
            </q-input>
            <q-space />
            <q-btn-group outline>
              <q-btn
                outline
                icon="add"
                no-wrap
                color="primary"
                label="新建"
                @click="add"
              />
              <q-btn
                outline
                color="primary"
                label="切换全屏"
                no-wrap
                v-if="$q.screen.gt.md"
                @click="table.toggleFullscreen"
                :icon="table.inFullscreen ? 'fullscreen_exit' : 'fullscreen'"
              />
              <q-btn-dropdown
                outline
                color="primary"
                label="自选列"
                icon="view_list"
                no-wrap
                v-if="$q.screen.gt.md"
              >
                <q-list>
                  <q-item tag="label" v-for="item in columns" :key="item.name">
                    <q-item-section avatar>
                      <q-checkbox v-model="group" :val="item.name" />
                    </q-item-section>
                    <q-item-section>
                      <q-item-label>{{ item.label }}</q-item-label>
                    </q-item-section>
                  </q-item>
                </q-list>
              </q-btn-dropdown>
              <q-btn
                outline
                no-wrap
                v-if="$q.screen.gt.sm"
                label="导入"
                icon="mdi-cloud-upload-outline"
                :loading="importing"
                color="primary"
                @click="importExcel"
              >
                <q-uploader
                  auto-upload
                  ref="excelUploader"
                  :max-files="1"
                  class="hidden"
                  :url="importExcelUrlFull"
                  field-name="file"
                  :headers="headers"
                  @uploaded="importedExcel"
                />
              </q-btn>
              <q-btn
                outline
                no-wrap
                v-if="$q.screen.gt.sm"
                :loading="exporting"
                label="导出"
                icon="mdi-cloud-download-outline"
                color="primary"
                @click="exportExcel('模块管理')"
              />
              <q-btn
                :disable="selected.length === 0"
                outline
                no-wrap
                v-if="$q.screen.gt.md"
                color="primary"
                label="批量删除"
                @click="showConfirm()"
                icon="mdi-delete-variant"
              />
            </q-btn-group>
          </div>
        </template>
        <template #body-cell-status="props">
          <q-td key="status" :props="props">
            {{ getDictLabel(yesNo, props.row.status) }}
          </q-td>
        </template>
        <template #body-cell-opt="props">
          <q-td :props="props" :auto-width="true">
            <q-btn
              flat
              round
              dense
              color="primary"
              icon="edit"
              @click="edit(props.row)"
            >
              <q-tooltip>编辑</q-tooltip></q-btn
            >
            <q-btn
              flat
              round
              dense
              color="primary"
              icon="mdi-content-copy"
              @click="copy(props.row)"
            >
              <q-tooltip>复制</q-tooltip>
            </q-btn>
            <btn-del label="模块管理" @confirm="del(props.row)" />
          </q-td>
        </template>
      </q-table>
    </div>
    <cc-dialog ref="dialog" :title="`${editType}模块管理`" @submit="submit">

            <div class="col-12">
              <h5><q-icon name="star" color="red" /> 模块编码：</h5>
              <q-input
                outlined
                dense
                v-model="form.moduleCode"
                type="text"
                :rules="[requiredTest]"
              />
            </div>
            <div class="col-12">
              <h5><q-icon name="star" color="red" /> 模块名称：</h5>
              <q-input
                outlined
                dense
                v-model="form.moduleName"
                type="text"
                :rules="[requiredTest]"
              />
            </div>
            <div class="col-12">
              <h5><q-icon name="star" color="red" /> 状态：</h5>
              <q-select
                outlined
                dense
                emit-value
                v-model="form.status"
                map-options
                :options="yesNo"
              />
            </div>
            <div class="col-12">
              <h5>模块首页地址：</h5>
              <q-input outlined dense v-model="form.url" type="text" />
            </div>
            <div class="col-12">
              <h5>模块图片：</h5>
              <q-input outlined dense v-model="form.img" type="text" />
            </div>
            <div class="col-12">
              <h5>模块图标：</h5>
              <q-input outlined dense v-model="form.moduleIcon" type="text" />
            </div>
            <div class="col-12">
              <h5>模块样式：</h5>
              <q-input outlined dense v-model="form.moduleClass" type="text" />
            </div>
           </cc-dialog>
    <confirm ref="confirmDialog" :msg="confirmMsg" @confirm="deleteBatch()" />
  </q-page>
</template>

<script>
import { IndexMixin } from 'boot/mixins';
import { getDictLabel } from 'boot/dictionary';
import confirm from 'components/confirm';
import { requiredTest } from 'boot/inputTest';

export default {
  name: 'SysModule',
  mixins: [IndexMixin],
  components: {
    confirm,
  },
  data() {
    return {
      columns: [
        {
          name: 'index',
          align: 'center',
          label: '序号',
          field: 'index',
          headerClasses: 'cc-table-index',
        },
        {
          name: 'moduleCode', align: 'center', label: '模块编码', field: 'moduleCode',
        },
        {
          name: 'moduleName', align: 'center', label: '模块名称', field: 'moduleName',
        },
        {
          name: 'status', align: 'center', label: '状态', field: 'status',
        },
        {
          name: 'url', align: 'center', label: '模块首页地址', field: 'url',
        },
        {
          name: 'img', align: 'center', label: '模块图片', field: 'img',
        },
        {
          name: 'moduleIcon', align: 'center', label: '模块图标', field: 'moduleIcon',
        },
        {
          name: 'moduleClass', align: 'center', label: '模块样式', field: 'moduleClass',
        },
        {
          name: 'opt', align: 'center', label: '操作', field: 'id',
        },
      ],
      yesNo: [{ value: '1', label: '是' }, { value: '0', label: '否' }],
      showQuery: true,
      headers: [{ name: 'Authorization', value: localStorage.Authorization }],
      uploadUrl: `${process.env.BASE_URL}/sys/common/upload`,
      imgUrl: `${process.env.BASE_URL}/sys/common/static`,
      url: {
        list: '/sys/module/list',
        add: '/sys/module/add',
        edit: '/sys/module/edit',
        copy:
          '/sys/module/copy',
        delete: '/sys/module/delete',
        deleteBatch: '/sys/module/deleteBatch',
        exportXlsUrl: '/sys/module/exportXls',
        importExcelUrl: '/sys/module/importExcel',
      },
    };
  },
  methods: {
    requiredTest,
    getDictLabel,
    initDict() {
    },
  },
  mounted() {
    this.initDict();
  },
};
</script>

<style lang="stylus"></style>
